<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<!--{include file='comm/header.tpl'}-->
<!--{include file='comm/comm_cal.tpl'}-->
<style>.flexigrid{margin:10px;}</style>
<title>订单促销编辑</title>
<!--{include file="comm/icheck.tpl"}-->
<!--{include file='comm/comm_pic.tpl'}-->
<script>
	var GIFT_ARRAY = { };
</script>
</head>
<body>
	<div style="width:100%;">
		
		<div class="container">

            <div class="comm_crub">
			    <span class="now_crub">订单促销编辑：
                    <span id="title">
                        <!--{if $promotionInfo->type == 1}-->
                            订单立减
                        <!--{elseif $promotionInfo->type == 2}-->
                            免运费
                        <!--{elseif $promotionInfo->type == 3}-->
                            优惠券
                        <!--{elseif $promotionInfo->type == 4}-->
                            折扣
                        <!--{/if}-->
                    </span>
                </span>
			</div>
			
			<div class="comm_content">
				<!--{if isset($error_msg)}-->
	            
					<div class="comm-box">
		                <div style="position:relative;color: red;">
		                    <!--{$error_msg}-->
		                </div>
		            </div>
	            <!--{else}-->
					<div>
						<form id="sendForm" name="sendForm" class="form-horizontal" onsubmit="return false;">
							<div>
                                <div class="form-group">
                                    <label for="title" class="col-sm-2 control-label"><span class="red">*</span> 促销标题：</label>
                                    <div class="col-sm-10">
                                        <input type="text" class="form-control w300" id="title" name="title" placeholder="请输入促销标题【必填项】"  value="<!--{$promotionInfo->title}-->" >
                                    </div>
                                    <input type="hidden" id="type" name="type" value="<!--{$promotionInfo->type}-->">
                                    <input type="hidden" id="promotionID" name="promotionID" value="<!--{$promotionInfo->promotionID}-->">
                                </div>

                                <div class="form-group">
                                    <label for="billAmount" class="col-sm-2 control-label"><span class="red">*</span> 下限金额：</label>
                                    <div class="col-sm-10">
                                        <input type="text" class="form-control w300" id="billAmount" name="billAmount" placeholder="请输入下限金额【必填项】"  value="<!--{$promotionInfo->billMoney}-->" >
                                    </div>
                                    <input type="hidden" id="type" name="type" value="<!--{$promotionInfo->type}-->">
                                    <input type="hidden" id="promotionID" name="promotionID" value="<!--{$promotionInfo->promotionID}-->">
                                </div>

                                <div class="form-group">
                                    <div>
                                        <label class="col-sm-2 control-label"><span class="red">*</span> 促销时间：</label>
                                        <div class="col-sm-3" >
                                            <input type="text" class="form-control"id="startTime" name="startTime" readonly=""  value="<!--{$promotionInfo->startDate}-->" >
                                        </div>
                                        <div class="fl">
                                            <label class="col-sm-1 control-label">～</label>
                                        </div>
                                        <div class="col-sm-3">
                                            <input type="text" class="form-control" id="endTime" name="endTime" readonly="" value="<!--{$promotionInfo->endDate}-->">
                                        </div>
                                    </div>
                                </div>

                                <div class="form-group">
                                    <div>
                                        <label class="col-sm-2 control-label"> 配送时间：</label>
                                        <div class="col-sm-2" style="width:130px;">
                                            <input type="text" class="form-control w100" id="sendStartTime" name="sendStartTime" readonly="" value="<!--{$promotionInfo->sendStartDate}-->">
                                        </div>
                                        <div class="fl">
                                            <label class="col-sm-1 control-label">～</label>
                                        </div>
                                        <div class="col-sm-2">
                                            <input type="text" class="form-control w100" id="sendEndTime" name="sendEndTime" readonly="" value="<!--{$promotionInfo->sendEndDate}-->" >
                                        </div>
                                    </div>
                                </div>

                                <div class="form-group" style="display:none;">
                                    <label for="priority" class="col-sm-2 control-label"><span class="red">*</span> 优先级：</label>
                                    <div class="col-sm-10">
                                        <input type="text" class="form-control w300" id="priority" name="priority" placeholder="请输入促销优先级【必填项】" value="<!--{$promotionInfo->priority}-->">
                                    </div>
                                </div>

                                <div class="form-group">
                                    <label  class="col-sm-2 control-label"><span class="red">*</span> 是否使用代金卡：</label>
                                    <div class="col-sm-10">

                                        <div class="fl" style="margin-right: 10px;">
                                            <input type="radio" class="square-radio" id="card-radio-2" name="use_card" value="2" <!--{if $promotionInfo->use_card eq 2}-->checked<!--{/if}-->>
                                            <label for="card-radio-2">不限</label>
                                        </div>
                                        <div class="fl" style="margin-right: 10px;">
                                            <input type="radio" class="square-radio" id="card-radio-1" name="use_card" value="1" <!--{if $promotionInfo->use_card eq 1}-->checked<!--{/if}-->>
                                            <label for="card-radio-1">是</label>
                                        </div>
                                        <div class="fl">
                                            <input type="radio" class="square-radio" id="card-radio-0" name="use_card" value="0" <!--{if $promotionInfo->use_card eq 0}-->checked<!--{/if}-->>
                                            <label for="card-radio-0">否</label>
                                        </div>
                                    </div>
                                </div>


                                    <div class="form-group" id="setUseCard"  <!--{if $promotionInfo->use_card neq 1}-->style="display:none;"<!--{/if}-->>
                                        <label class="col-sm-2 control-label">
                                            <span class="red">*</span>
                                            代金卡面值：
                                        </label>
                                        <div class="col-sm-10">
                                            <!--{foreach from=$card_array item=card}-->
                                            <div class="fl" style="margin: 0px 10px 10px 0px;">
                                                <input type="checkbox" class="square-radio" id="card-checkbox-<!--{$card.face_value}-->" name="use_card_face_value" value="<!--{$card.face_value}-->" <!--{if isset($promotionInfo->use_card_face_value) && $card.face_value|in_array:$promotionInfo->use_card_face_value}--> checked="checked" <!--{/if}-->>
                                                <label for="card-checkbox<!--{$card.face_value}-->"><!--{$card.face_value}--></label>
                                            </div>
                                            <!--{/foreach}-->
                                        </div>
                                    </div>




                                <div class="form-group">
                                    <label  class="col-sm-2 control-label"><span class="red">*</span> 是否使用优惠券：</label>
                                    <div class="col-sm-10">
                                        <!--{if $promotionInfo->use_coupon == 2}-->
                                        <div class="fl" style="margin-right: 10px;">
                                            <input type="radio" class="square-radio" id="coupon-radio-2" name="use_coupon" value="2" checked>
                                            <label for="coupon-radio-2">不限</label>
                                        </div>
                                        <div class="fl" style="margin-right: 10px;">
                                            <input type="radio" class="square-radio" id="coupon-radio-1" name="use_coupon" value="1">
                                            <label for="coupon-radio-1">是</label>
                                        </div>
                                        <div class="fl">
                                            <input type="radio" class="square-radio" id="coupon-radio-0" name="use_coupon" value="0">
                                            <label for="coupon-radio-0">否</label>
                                        </div>
                                        <!--{elseif $promotionInfo->use_coupon == 1}-->
                                        <div class="fl" style="margin-right: 10px;">
                                            <input type="radio" class="square-radio" id="coupon-radio-2" name="use_coupon" value="2" >
                                            <label for="coupon-radio-2">不限</label>
                                        </div>
                                        <div class="fl" style="margin-right: 10px;">
                                            <input type="radio" class="square-radio" id="coupon-radio-1" name="use_coupon" value="1" checked>
                                            <label for="coupon-radio-1">是</label>
                                        </div>
                                        <div class="fl">
                                            <input type="radio" class="square-radio" id="coupon-radio-0" name="use_coupon" value="0">
                                            <label for="coupon-radio-0">否</label>
                                        </div>
                                        <!--{else}-->
                                        <div class="fl" style="margin-right: 10px;">
                                            <input type="radio" class="square-radio" id="coupon-radio-2" name="use_coupon" value="2" >
                                            <label for="coupon-radio-2">不限</label>
                                        </div>
                                        <div class="fl" style="margin-right: 10px;">
                                            <input type="radio" class="square-radio" id="coupon-radio-1" name="use_coupon" value="1">
                                            <label for="coupon-radio-1">是</label>
                                        </div>
                                        <div class="fl">
                                            <input type="radio" class="square-radio" id="coupon-radio-0" name="use_coupon" value="0" checked>
                                            <label for="coupon-radio-0">否</label>
                                        </div>
                                        <!--{/if}-->
                                    </div>
                                </div>

                                <div class="form-group" style="display: none;">
                                    <label  class="col-sm-2 control-label"> 是否排斥：</label>
                                    <div class="col-sm-10">
                                        <!--{if $promotionInfo->repel == 1}-->
                                        <div class="fl" style="margin-right: 10px;">
                                            <input type="radio" class="square-radio" id="repel-radio-1" name="repel" value="1" checked>
                                            <label for="repel-radio-1">是</label>
                                        </div>
                                        <div class="fl">
                                            <input type="radio" class="square-radio" id="repel-radio-0" name="repel" value="0">
                                            <label for="repel-radio-0">否</label>
                                        </div>
                                        <!--{elseif $promotionInfo->repel == 0}-->
                                        <div class="fl" style="margin-right: 10px;">
                                            <input type="radio" class="square-radio" id="repel-radio-1" name="repel" value="1">
                                            <label for="repel-radio-1">是</label>
                                        </div>
                                        <div class="fl">
                                            <input type="radio" class="square-radio" id="repel-radio-0" name="repel" value="0" checked>
                                            <label for="repel-radio-0">否</label>
                                        </div>
                                        <!--{/if}-->
                                    </div>
                                </div>

                                <div class="form-group">
                                    <label class="col-sm-2 control-label"> 使用状态：</label>
                                    <div class="col-sm-10">
                                        <!--{if $promotionInfo->useFlg == 1}-->
                                        <div class="fl" style="margin-right: 10px;">
                                            <input type="radio" class="square-radio" id="square-radio-1" name="useFlg" value="1" checked>
                                            <label for="square-radio-1">启用</label>
                                        </div>
                                        <div class="fl">
                                            <input type="radio" class="square-radio" id="square-radio-0" name="useFlg" value="0">
                                            <label for="square-radio-0">禁用</label>
                                        </div>
                                        <!--{elseif $promotionInfo->useFlg == 0}-->
                                        <div class="fl" style="margin-right: 10px;">
                                            <input type="radio" class="square-radio" id="square-radio-1" name="useFlg" value="1">
                                            <label for="square-radio-1">启用</label>
                                        </div>
                                        <div class="fl">
                                            <input type="radio" class="square-radio" id="square-radio-0" name="useFlg" value="0" checked>
                                            <label for="square-radio-0">禁用</label>
                                        </div>
                                        <!--{/if}-->
                                    </div>
                                </div>

                                <div class="form-group">
                                    <label for="description" class="col-sm-2 control-label"> 促销描述：</label>
                                    <div class="col-sm-8">
                                        <textarea  class="form-control" id="description" name="description" placeholder="请输入促销描述" ><!--{$promotionInfo->remark}--></textarea>
                                    </div>
                                </div>

                                <div class="form-group">
                                    <label class="col-sm-2 control-label">会员等级：</label>
                                    <div class="col-sm-10">
                                        <!--{foreach from=$cust_rank_array item=cust}-->
                                        <div class="fl" style="margin: 0px 10px 10px 0px;">
                                            <input type="checkbox" class="square-radio" id="rank-checkbox-<!--{$cust.rankID}-->" name="rankID" value="<!--{$cust.rankID}-->" <!--{if isset($promotionInfo->rankID) && $cust.rankID|in_array:$promotionInfo->rankID}--> checked="checked" <!--{/if}-->>
                                            <label for="rank-checkbox-<!--{$cust.rankID}-->"><!--{$cust.rankName}--></label>
                                        </div>
                                        <!--{/foreach}-->
                                    </div>
                                </div>

                                <div class="form-group">
                                    <label class="col-sm-2 control-label">支付方式：</label>
                                    <div class="col-sm-10">
                                        <!--{foreach from=$pay_type_array item=payType}-->
                                        <div class="fl" style="margin: 0px 10px 10px 0px;">
                                            <input type="checkbox" class="square-radio" id="payType-checkbox-<!--{$payType.payTypeID}-->" name="payTypeID" value="<!--{$payType.payTypeID}-->" <!--{if isset($promotionInfo->payTypeID) && $payType.payTypeID|in_array:$promotionInfo->payTypeID}--> checked="checked" <!--{/if}--> >
                                            <label for="payType-checkbox-<!--{$payType.payTypeID}-->"><!--{$payType.payTypeName}--></label>
                                        </div>
                                        <!--{/foreach}-->
                                    </div>
                                </div>

                                <!--付款方式-->
                                <div class="form-group" id="payment" style="<!--{if !$payment_array}-->display:none<!--{/if}-->">
                                    <label class="col-sm-2 control-label">付款方式：</label>
                                    <div class="col-sm-10">
                                        <!--{foreach from=$payment_array item=payment}-->
                                        <div class="fl" style="margin: 0px 10px 10px 0px;">
                                            <input type="checkbox" class="square-radio" id="payment-checkbox-<!--{$payment.id}-->" name="paymentID" value="<!--{$payment.payTypeID}-->-<!--{$payment.id}-->" <!--{if isset($select_paymentID) && $payment.id|in_array:$select_paymentID}--> checked="checked" <!--{/if}--> >
                                            <label for="payment-checkbox-<!--{$payment.id}-->"><!--{$payment.name}--></label>
                                        </div>
                                        <!--{/foreach}-->
                                    </div>
                                </div>
                                <!--付款方式-->

                                <div class="form-group">
                                    <label class="col-sm-2 control-label">促销渠道：</label>
                                    <div class="col-sm-10">
                                        <!--{foreach from=$promotion_channel_array item=promotionChannel}-->
                                        <div class="fl" style="margin: 0px 10px 10px 0px;">
                                            <input type="checkbox" class="square-radio" id="promotionChannel-checkbox-<!--{$promotionChannel.itemID}-->" name="promotionChannelID" value="<!--{$promotionChannel.itemID}-->" <!--{if isset($promotionInfo->promotionChannelID) && $promotionChannel.itemID|in_array:$promotionInfo->promotionChannelID}--> checked="checked" <!--{/if}--> >
                                            <label for="promotionChannel-checkbox-<!--{$promotionChannel.itemID}-->"><!--{$promotionChannel.itemName}--></label>
                                        </div>
                                        <!--{/foreach}-->
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="col-sm-2 control-label">城市：</label>
                                    <div class="col-sm-10">
                                        <!--{foreach from=$city_array item=city}-->
                                        <div class="fl" style="margin: 0px 10px 10px 0px;">
                                            <input type="checkbox" class="square-radio" id="city-checkbox-<!--{$city.id}-->" name="cityID" value="<!--{$city.id}-->" <!--{if isset($promotionInfo->cityID) && $city.id|in_array:$promotionInfo->cityID}--> checked="checked" <!--{/if}--> >
                                            <label for="city-checkbox-<!--{$city.id}-->"><!--{$city.name}--></label>
                                        </div>
                                        <!--{/foreach}-->
                                    </div>
                                </div>
							</div>

							<div>
								<!--{if $promotionInfo->type == 1}-->
                                    <div class="form-group">
                                        <label for="concessions_<!--{$promotionInfo->type}-->" class="col-sm-2 control-label"><span class="red">*</span> 立减金额：</label>
                                        <div class="col-sm-10">
                                            <input type="text" class="form-control w300" id="concessions_<!--{$promotionInfo->type}-->" name="concessions_<!--{$promotionInfo->type}-->" placeholder="请输入立减金额【必填项】"  value="<!--{$promotionInfo->subtractMoney}-->" >
                                        </div>
                                    </div>

                                    <div class="form-group">
                                        <label class="col-sm-2 control-label" data-toggle="dropdown"> 商品规则：</label>
                                        <div class="col-sm-10">
                                            <select class="form-control w150 fl" name="selectorID_<!--{$promotionInfo->type}-->" id="selectorID_<!--{$promotionInfo->type}-->" >
                                                <option value="" selected>请选择</option>
                                                <!--{foreach from=$promotionInfo->goodsSelector item=s_l}-->
                                                <option value="<!--{$s_l->selectID}-->"><!--{$s_l->selectName}--></option>
                                                <!--{/foreach}-->
                                            </select>
                                        </div>
                                    </div>

								<!--{elseif $promotionInfo->type == 2 }-->
                                    <div class="form-group">
                                        <label class="col-sm-2 control-label" data-toggle="dropdown"> 商品规则：</label>
                                        <div class="col-sm-10">
                                            <select class="form-control w150 fl" name="selectorID_<!--{$promotionInfo->type}-->" id="selectorID_<!--{$promotionInfo->type}-->" >
                                                <option value="" selected>请选择</option>
                                                <!--{foreach from=$promotionInfo->goodsSelector item=s_l}-->
                                                <option value="<!--{$s_l->selectID}-->"><!--{$s_l->selectName}--></option>
                                                <!--{/foreach}-->
                                            </select>
                                        </div>
                                    </div>
								<!--{elseif $promotionInfo->type == 3}-->
                                    <div class="form-group">
                                        <label class="col-sm-2 control-label" data-toggle="dropdown"> 商品规则：</label>
                                        <div class="col-sm-10">
                                            <select class="form-control w150 fl" name="selectorID_<!--{$promotionInfo->type}-->" id="selectorID_<!--{$promotionInfo->type}-->" >
                                                <option value="" selected>请选择</option>
                                                <!--{foreach from=$promotionInfo->goodsSelector item=s_l}-->
                                                <option value="<!--{$s_l->selectID}-->"><!--{$s_l->selectName}--></option>
                                                <!--{/foreach}-->
                                            </select>
                                        </div>
                                    </div>
                                    <input type="text" name="bill_status" value="4" id="bill_status" style="display: none;">
                                    <div class="form-group">
                                        <label for="bill_status" class="col-sm-2 control-label"> 发放订单状态：</label>
                                        <div class="col-sm-10">
                                            <select class="form-control w150 fl" name="bill_status" id="bill_status" >
                                                <option value="0" <!--{if $promotionInfo->bill_status eq 0}-->selected<!--{/if}-->>订单建立</option>
                                                <option value="4" <!--{if $promotionInfo->bill_status eq 4}-->selected<!--{/if}-->>订单完成</option>
                                            </select>
                                        </div>
                                    </div>

                                    <div class="form-group">
                                        <div>
                                            <label class="col-sm-2 control-label"><span class="red">*</span> 优惠券：</label>
                                            <div class="col-sm-10">
                                                <table id="couponTable">
                                                    <tbody>
                                                    <!--{foreach from=$promotionInfo->coupon_detail key=coupon_k item=coupon_l}-->
                                                        <tr id="addCouponTr_<!--{$coupon_k+1}-->">
                                                            <td class="td_input" style="height:35px;">
                                                                <!--{if $coupon_k == 0}-->
                                                                <div class="col-sm-3" style="margin:0 -15px" >
                                                                    <input type="text" class="form-control" id="couponNum_1" name="couponNum_1" maxlength="7" autocomplete="off" value="<!--{$coupon_l->couponNum}-->"  style="ime-mode:active;" >
                                                                </div>
                                                                <div class="fl">
                                                                    <label class="col-sm-1 control-label">张</label>
                                                                </div>
                                                                <select class="form-control fl" style="width: 250px;" name="couponCode_1" id="couponCode_1" >
                                                                    <option value="" selected>请选择</option>
                                                                    <!--{foreach from=$promotionInfo->coupon item=c_l}-->
                                                                    <option value="<!--{$c_l->couponID}-->" <!--{if $coupon_l->couponID == $c_l->couponID}-->selected<!--{/if}--> ><!--{$c_l->couponName}--></option>
                                                                    <!--{/foreach}-->
                                                                </select>
                                                                <input type="button" style="margin:0 20px;"  onclick="promotion.coupoonList();" class="btn btn-success" value="添加">
                                                                <!--{else}-->
                                                                <div class="col-sm-3" style="margin:0 -15px" >
                                                                    <input type="text" class="form-control" id="couponNum_<!--{$coupon_k+1}-->" name="couponNum_<!--{$coupon_k+1}-->" maxlength="7" autocomplete="off" value="<!--{$coupon_l->couponNum}-->"  style="ime-mode:active;" >
                                                                </div>
                                                                <div class="fl">
                                                                    <label class="col-sm-1 control-label">张</label>
                                                                </div>
                                                                <select class="form-control fl" style="width: 250px;" name="couponCode_<!--{$coupon_k+1}-->" id="couponCode_<!--{$coupon_k+1}-->" >
                                                                    <option value="" selected>请选择</option>
                                                                    <!--{foreach from=$promotionInfo->coupon item=c_l}-->
                                                                    <option value="<!--{$c_l->couponID}-->" <!--{if $coupon_l->couponID == $c_l->couponID}-->selected<!--{/if}--> ><!--{$c_l->couponName}--></option>
                                                                    <!--{/foreach}-->
                                                                </select>
                                                                <input type="button" style="margin:0 20px;" class="btn btn-default"  onclick="promotion.delCoupon(<!--{$coupon_k+1}-->);" value="移除">
                                                                <!--{/if}-->
                                                            </td>
                                                        </tr>
                                                    <!--{/foreach}-->
                                                    </tbody>
                                                </table>
                                            </div>
                                        </div>
                                    </div>


                                <!--{elseif $promotionInfo->type == 4}-->
                                <div class="form-group">
                                    <label  class="col-sm-2 control-label"><span class="red">*</span> 折扣：</label>
                                    <div class="col-sm-10">
                                        <input type="text" class="form-control w300" id="concessions_<!--{$promotionInfo->type}-->" name="concessions_<!--{$promotionInfo->type}-->" placeholder="请输入折扣数【必填项】"  value="<!--{$promotionInfo->subtractMoney}-->" >
                                    </div>
                                </div>

                                <div class="form-group">
                                    <label class="col-sm-2 control-label" data-toggle="dropdown"> 商品规则：</label>
                                    <div class="col-sm-10">
                                        <select class="form-control w150 fl" name="selectorID_<!--{$promotionInfo->type}-->" id="selectorID_<!--{$promotionInfo->type}-->" >
                                            <option value="" selected>请选择</option>
                                            <!--{foreach from=$promotionInfo->goodsSelector item=s_l}-->
                                            <option value="<!--{$s_l->selectID}-->"><!--{$s_l->selectName}--></option>
                                            <!--{/foreach}-->
                                        </select>
                                    </div>
                                </div>

                                <!--{/if}-->
							</div>

						</form>
					</div>
					
				<!--{/if}-->
			</div>
		</div>
		</div>

		<div class="popup-footer">
	        <div class="rectbox tac" style="margin: 20px;">
	        	<input type="hidden" id ="dataCache" name="dataCache" value="">
	            <input type="button" class="btn btn-success" onclick="promotion.check();" value="保存" />&nbsp;&nbsp;&nbsp;
	            <input type="button" class="btn btn-default" onclick="E.closeWindows();" value="关闭" />
	        </div>
	    </div>

	</div>
	<div id="send_cover" class="e_cover_layer hide" style="z-index:499;"></div>
	<div id="send_layer" class="e_layer hide" style="z-index:500;">
		<table style="border-collapse: collapse;margin: 0 auto;width: 300px;">
			<tr>
				<td>
					<div class="content" style="top:-15px;"></div>
				</td>
			</tr>
		</table>
	</div>
	<script>

        $(window).ready(function() {

            $('.square-radio').iCheck({
                checkboxClass: 'icheckbox_square-blue',
                radioClass: 'iradio_square-blue',
                increaseArea: '20%' // optional
            });

            $('input[name="use_card"]').on('ifChecked', function(){ //代金卡面值
                var use_card = $(this).val();

                if ( use_card == 0 ) {

                    $("#setUseCard").hide();

                } else if ( use_card == 2 ){

                    $("#setUseCard").hide();

                } else {

                    $("#setUseCard").show();

                }

            });

            $('input[name="payTypeID"]').on('ifChanged', function() {

                promotion.getPaymen();

            });


        });
		if( GIFT_ARRAY )
			$("#dataCache").data( "goods" , GIFT_ARRAY );


		var GTYPE = "<!--{$promotionInfo->type}-->" ;		
		var COUPONFLG = 100;	//添加优惠券行标志	
		var promotion = {
			
			//添加优惠券输入行
			coupoonList : function(){
				select_str = $('#couponCode_1').html();

                var tr_str = '<tr id=addCouponTr_'+COUPONFLG+' style="height:35px;">';
                tr_str += '<td class="td_input">';
                tr_str += '<div class="col-sm-3" style="margin:0 -15px" >';
                tr_str += '<input id=couponNum_'+COUPONFLG+' type="text" class="form-control" name=couponNum_'+COUPONFLG+' maxlength="7" autocomplete="off"  style="ime-mode:active;" >';
                tr_str += '</div>';
                tr_str += '<div class="fl">';
                tr_str += '<label class="col-sm-1 control-label">张</label>';
                tr_str += '</div>';
                tr_str += '<select name=couponCode_'+COUPONFLG+' id=couponCode_'+COUPONFLG+' class="form-control fl" style="width: 250px;" >';
                tr_str += select_str;
                tr_str += '</select>';
                tr_str += ' <input type="button" class="btn btn-default" style="margin:0 20px;" onclick=promotion.delCoupon('+COUPONFLG+') value="移除">';
                tr_str += '</td>';
                tr_str += '</tr>';

                COUPONFLG++
                $('#couponTable').append(tr_str);
			},
			
			//删除添加优惠券的行
			delCoupon : function(flg){
				$('#addCouponTr_'+flg).remove();
			},

			//自动编辑一行数据
			addLine: function ( goodsLen ){
				var sku		  = $.trim($("#sku").attr("title")) ; 		//商品sku
				var postID	  = $.trim($("#sku").attr("name")) ; 		//商品postID
				var goodsName = $.trim($("#goodsName").html()) ; 		//商品名称
				var spec	  = $.trim($("#spec").html()) ; 			//商品规格
				var salePrice = $.trim($("#salePrice").attr("title")) ; //商品销售价
				var saleAmount= $.trim($("#saleAmount").val()) ; 		//商品数量
				var rowClass  = goodsLen%2 == 0 ? '' : 'erow' ;
				var htmlLine =  '<tr id="row_' + postID + '" class="' + rowClass + '" onclick="doDelect('+ postID +')">' ; 
					htmlLine += '	<td class="">' ;
					htmlLine += '		<div style="width: 90px;height:30px;" class="sundefined">' ;
					htmlLine += 			sku ;
					htmlLine += '		</div>' ;
					htmlLine += '	</td>' ;
					htmlLine += '	<td class="">' ;
					htmlLine += '		<div style="width: 260px;" class="sundefined">' ;
					htmlLine += 			goodsName ;
					htmlLine += '		</div>' ;
					htmlLine += '	</td>' ;
					htmlLine += '	<td class="">' ;
					htmlLine += '		<div style="width: 120px;" class="sundefined">' ;
					htmlLine += 			spec ;
					htmlLine += '		</div>' ;
					htmlLine += '	</td>' ;
					htmlLine += '	<td class="">' ;
					htmlLine += '		<div style="width: 80px;" class="sundefined">' ;
					htmlLine +=				salePrice ;
					htmlLine += '		</div>' ;
					htmlLine += '	</td>' ;
					htmlLine += '	<td>' ;
					htmlLine += '		<div style="width: 50px;">' ;
					htmlLine += 			saleAmount ;		
					htmlLine += '		</div>';
					htmlLine += '	</td>' ;
					htmlLine += '</tr>' ; 

				$("#goodsTable").append(htmlLine) ;
				
			},
			
			//ajax 回调函数
	        getGoodsInfoCallBack : function (response){
	            if(response.code != 200){
	                $("#sku").val("") ;
	                E.alert(response.message);
	                $("#sku").focus() ;
	                return false;
	            }
	            $("#sku").attr("name" , response.data.postID) ;
				$("#sku").attr("title" , response.data.sku) ;
				$("#goodsName").html( response.data.goodsName ) ;
				$("#spec").html( response.data.spec ) ;
				$("#salePrice").html( 0) ;
				$("#saleAmount").val(1) ;
				$("#salePrice").val(0) ;
				$("#salePrice").focus() ;
				
	        },
	        
	        //清除行里的数据
	        clear: function () {
	        	$("#sku").val("") ;
	        	$("#sku").attr("title", "") ;
	        	$("#sku").attr("name", "") ;
	        	$("#goodsName").html("") ;
	        	$("#spec").html("") ;
	        	$("#salePrice").val("") ;
	        	$("#saleAmount").val("") ;
	        },
	        removeRow:function () {
	        	//删除选择的商品
	            $(".trSelected").each(function (k,v){
	                var id = $(this).parent().parent().attr("id");
	              	var idArr = id.split("_") ;
	              	postID = idArr[1] ;
	              	if( postID !=0 ) {
	              		//移出这一行
	              		$("#row_" + postID).remove() ;
	              		
	              		//读取data
	              		var goods_obj = $("#dataCache").data("goods")
						if(goods_obj){
							$.each(goods_obj,function(k,v){
								if( postID == k )
									delete(goods_obj[k])
							});
						}
						//保存商品到data
						$("#dataCache").data( "goods" , goods_obj )
						
	              	}
	              	
	            });
	        }
	        ,
			//检查数据
	        check: function() {
				this.dt = E.getFormValues("sendForm") ;
				
	            var concessions = $.trim($("#concessions_" + GTYPE).val()) ;
	            var error_msg = "";
	            if (this.dt.title == "")
	                error_msg += "促销标题不能为空<br />";
	                
	            if (!E.isDate(this.dt.startTime))
	                error_msg += "促销开始时间格式不对<br />";
				
				if (!E.isDate(this.dt.endTime))
					error_msg += "促销结束时间格式不对<br />";
				
				if(this.dt.startTime > this.dt.endTime)   
					error_msg += "促销开始时间不能大于结束时间<br />";

                if(this.dt.sendStartTime > this.dt.sendEndTime)
                    error_msg += "配送开始时间不能大于结束时间<br />";

                if (this.dt.billAmount == "" ||  !E.isMoney(this.dt.billAmount))
                    error_msg += "输入的下限金额格式不对<br />";


                if (parseFloat(concessions) > parseFloat(this.dt.billAmount) ){
                    error_msg += "立减金额不可以大于下限金额<br/>";
                }

                if(this.dt.use_card == 1 && $.isEmptyObject(this.dt.use_card_face_value)){
                    error_msg += '请选择代金卡面值<br/>';
                }


	            if( GTYPE == 1 ){
	            	if(!E.isMoney(concessions))
	            		error_msg += "输入的立减金额格式不对<br />" ;
	            	
	            }else if( GTYPE == 3 ){
	            	//优惠券张数 	
	            	$.each($('[name*=couponNum_]'), function(k, v){
	            		var couponNum = $.trim($(v).val());
	            		if(!E.isInt(couponNum) || couponNum == 0){
	            			error_msg += "优惠券的张数必须为正整数<br />";
	            			return false;
	            		}	
	            	})	
	            	
	            	//优惠券编号
	            	var couponType = [];
	            	$.each($('[name*=couponCode_]'), function(k, v){
	            		var couponCode = $.trim($(v).val());
	            		if(!E.isInt(couponCode) || couponCode == 0){
	            			error_msg += "优惠券的编号必须为正整数<br />";
	            			return false;
	            		}
	            		couponType.push(couponCode);
	            	})	
	            	
	            	//判断数组中是否存在同一元素
	            	var repeat = promotion.checkRepeat(couponType);
	            	if(repeat)
	            		error_msg += "优惠券类型不能重复<br />";
	            	
	            	//添加优惠券行数参数
	            	var couponObj = [];
	            	$.each($('[name*=couponNum_]'), function(k, v){
	            		var numID = $(v).attr('id');
	            		var numArray = numID.split('_');
	            		
	            		//获取优惠券张数和优惠券编号
	            		var couponNum = $('#couponNum_'+numArray[1]).val();
	            		var couponID  = $('#couponCode_'+numArray[1]).val();
	            		couponObj.push([couponNum, couponID]);
	            	})
	            	this.dt['couponLine'] = couponObj;
	
	            }
	          			    
	            if (error_msg != "")
	                E.alert(error_msg);
	            else
	                promotion.add() ;
	        },
				
			//保存促销信息
	        add: function() {
	            $.ajax({
	                type: "POST",
	                url: "/invokingAjax-backend/promotion/promotionBill.ajax?operFlg=100&act=edit" ,
	                dataType: "JSON",
	                data: this.dt,
	                success: function( result_obj ) {
	                    if (result_obj.code == 200) {
                        	E.opener("promotion.load");
                        	E.alert(result_obj.message, 2, "E.closeWindows");
	                    } else {
	                        E.alert(result_obj.message);
	                    }
	                }
	            });
	        },


            //查询支付方式下的付款方式
            getPaymen:function( payTypeID ){

                var dt = E.getFormValues("sendForm");

                E.loadding.open('正在努力加载中...');

                E.ajax_post({
                    url: '/invokingAjax-backend/promotion/promotionBill.ajax?operFlg=7',
                    data: dt,
                    call: 'promotion.getPaymenCallBack'
                });
            },

            getPaymenCallBack:function( result_data ){

                E.loadding.close();

                if( result_data.code == 200 ){

                    if(result_data.data){
                        var html = '<label class="col-sm-2 control-label">付款方式：</label>';
                        html += '<div class="col-sm-10">'
                        $.each(result_data.data,function(k,v){
                            var checked = '';
                            if(v.select == 1){
                                checked = 'checked';
                            }
                            html += '<div class="fl" style="margin: 0px 10px 10px 0px;">';
                            html += '<input type="checkbox" class="square-radio-payment" id="payment-checkbox-'+ v.paymentID +'" name="paymentID" value="'+ v.payTypeID + '-' + v.paymentID +'" '+ checked +'>';
                            html += '<label for="payment-checkbox-'+ v.paymentID +'">'+ v.name +'</label>';
                            html += '</div>';

                        });
                        html += '</div>';

                        $("#payment").html(html).show()

                        $('.square-radio-payment').iCheck({
                            checkboxClass: 'icheckbox_square-blue',
                            radioClass: 'iradio_square-blue',
                            increaseArea: '20%' // optional
                        });

                    }else{
                        $("#payment").empty().hide();
                    }

                }else{

                    E.alert(result_data.message);

                }

            },

	        
	        //检查数组中是否有重复的元素
	        checkRepeat : function(a){
	        	return /(\x0f[^\x0f]+)\x0f[\s\S]*\1/.test("\x0f"+ a.join("\x0f\x0f") +"\x0f");
	        }
		};
		
		$(document).ready(function(){
			var selectorID  = "<!--{$promotionInfo->selectorID}-->" ;
			var bill_status = "<!--{$promotionInfo->bill_status}-->" ;
			var couponCode  = "<!--{$promotionInfo->couponCode}-->" ;
			if(selectorID != "")
				$("#selectorID_<!--{$promotionInfo->type}-->").val(selectorID) ;
				
			if(bill_status != "")
				$("#bill_status").val(bill_status) ;
				
			if(couponCode != "")
				$("#couponCode").val(couponCode) ;
			
			//商品输入商品编码回车
		    $("#sku").keydown(function(e){
		        if(e.keyCode == 13){
		        	var goodsSku = $.trim($("#sku").val()) ;
		        	if(goodsSku == "") {
		        		 E.alert('请输入商品编码');
		        		 return false ;
		        	}
		        	
		        	//检查商品sku是否已经存在
		        	var goods_obj = $("#dataCache").data("goods")
					if(goods_obj){
						var flg = 0
						$.each(goods_obj,function(k,v){
							if(goodsSku == v[0])
								flg = 1;
						});
						
						if(flg == 1){
							E.alert("已经存在商品SKU「" +  goodsSku + "」的商品");
							$("#sku").focus() ;
							return false;
						}
					}
		        	
					promotion_ajax( 6, {sku : goodsSku } , promotion.getGoodsInfoCallBack ) ;
		        }
		    });
			
		    
		    //销售价格回车
		    $("#salePrice").keydown(function(e){
		        if(e.keyCode == 13){
		        	var salePrice = $.trim($("#salePrice").val()) ;
		        	if(goodsName == "")
		        		return false ;	
		        	if(salePrice == "" || !E.isMoney(salePrice)) {
		        		 E.alert('请输入正确的商品价格');
		        		 return false ;
		        	}
		        	$("#salePrice").attr("title" ,salePrice) ;
					$("#saleAmount").focus() ;
		        }
		    });
		    
		    
		     //销售价格失去焦点
		    $("#salePrice").blur(function(e){
	        	var salePrice = $.trim($("#salePrice").val()) ;
	        	if(goodsName == "")
	        		return false ;	
	        	if(salePrice == "" || !E.isMoney(salePrice)) {
	        		 E.alert('请输入正确的商品价格');
	        		 return false ;
	        	}
	        	$("#salePrice").attr("title" ,salePrice) ;
				$("#saleAmount").focus() ;
		        
		    });
		    
		    //商品数量回车
		    $("#saleAmount").keydown(function(e){
		        if(e.keyCode == 13){
		        	var saleAmount = $.trim($("#saleAmount").val()) ;
		        	var postID 	   = $("#sku").attr("name") ;
		        	var goodsSku   = $.trim($("#sku").attr("title")) ;
		        	var goodsName  = $.trim($("#goodsName").html()) ;
		        	var salePrice  = $.trim($("#salePrice").attr("title")) ;
		        	if(goodsName == "")
		        		return false ;
		        		
		        	if(saleAmount == "" || !E.isInt(saleAmount)) {
		        		 E.alert('请输入正确的商品数量');
		        		 return false ;
		        	}
		        	
		        	var goods_obj = $("#dataCache").data("goods");
					if(!goods_obj)
						goods_obj = { };
					
					goods_obj[postID] =[goodsSku ,postID ,saleAmount ,salePrice];
					$("#dataCache").data("goods",goods_obj);
					var goodsLen = $("#goodsTable tr").length
					promotion.addLine( goodsLen ) ;
					promotion.clear() ;
					$("#sku").focus() ;
					
		        }
		    });
		    
		    //当数量失去焦点
		    $("#saleAmount").blur(function(e){
		    	var saleAmount = $.trim($("#saleAmount").val()) ;	
	        	var goodsName  = $.trim($("#goodsName").html()) ;
		      	if(goodsName != ""){
		      		if(saleAmount == "" || !E.isInt(saleAmount)) {
		        		 E.alert("请输入正确的商品数量");
		        		 $("#saleAmount").focus() ;
		        		 return false ;
		        	}
		      	}
		    });
		    
		})
		
		//选中要删除的行
		function doDelect ( postID ){
			var className = $("#row_" + postID).attr("class") ;
			if(className == "")
				$("#row_" + postID).addClass("trSelected") ;
			else
				$("#row_" + postID).removeClass("trSelected") ;
			if(className == "erow")
				$("#row_" + postID).addClass("trSelected erow") ;
	
			if(className == "trSelected erow")
				$("#row_" + postID).removeClass("trSelected") ;
		}
		
		//查询商品ajax 
	    function promotion_ajax( flg , data , func   ){
	        $.ajax({
	            type: "post",
	            url: "/invokingAjax-backend/promotion/promotionBill.ajax?operFlg=" + flg ,
	            dataType: "json",
	            data: data,
	            success: function( result_obj ) {
	                func(result_obj);
	            },
	            error : function(msg){
	                E.alert('网络不给力，请重新尝试...',1);
	            }
	        });
    	}
	</script>
	<script>
        $('#startTime').datetimepicker({timeFormat:'HH:mm:ss',showHour: true,showMinute: true,showSecond: true,});
        $('#endTime').datetimepicker({timeFormat:'HH:mm:ss',showHour: true,showMinute: true,showSecond: true,hour: 23,minute: 59,second:59,});

        $('#sendStartTime').datetimepicker();
        $('#sendEndTime').datetimepicker();
	</script>
</body>
</html>